package com.ljx.itbbs.server.mall.service.strategy;

import com.ljx.itbbs.server.article.domain.entity.ResourceEntity;
import com.ljx.itbbs.server.article.service.ResourceService;
import com.ljx.itbbs.server.mall.domain.enums.OrderTypeEnum;
import com.ljx.itbbs.server.mall.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: LiJunXi
 * @Description: 文章资源订单处理
 * @Date: 2024-03-29  17:26
 */
@Component
public class ArticleResourceOrderHandler extends AbstractOrderHandler<ResourceEntity>{

    @Autowired
    private ResourceService resourceService;

    @Autowired
    private OrderService orderService;

    /**
     * 获取订单枚举类
     * @return
     */
    @Override
    OrderTypeEnum getOrderTypeEnum() {
        return OrderTypeEnum.ARTICLE_RESOURCE;
    }

    /**
     * 获取订单商品对象ID【类型 + 原id】
     * @param objId
     * @return
     */
    @Override
    String getOrderObjId(Long objId) {
        return OrderTypeEnum.getObjId(objId, getOrderTypeEnum());
    }

    /**
     * 获取订单描述
     * @param objId
     * @return
     */
    @Override
    String getOrderDesc(Long objId) {
        ResourceEntity resource = resourceService.getById(objId);
        String title = getOrderTypeEnum().getDesc();
        return String.format("[%s]%s", title, resource.getFilename());
    }
}
